<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
    <meta name="format-detection" content="telephone=no, email=no"/>
    <meta name="apple-mobile-web-app-capable" content="yes"/>
    <meta name="apple-mobile-web-app-status-bar-style" content="black"/>
    <title>Title</title>
</head>
<body>
</body>

<script>
    //数组去重
    //第一种方法
    var arr = [23, 23, 1, 1, 1235, 1245, 1245, 88, 66, 88, 1235];
    Array.prototype.unique1 = function () {
        var n = [];
        for (var i = 0; i < this.length; i++) {
            if (n.indexOf(this[i]) == -1)
                n.push(this[i]);
        }
        return n;
    };

    console.log(arr)
    //第二种方法
    Array.prototype.unique3 = function () {
        var n = {}, r = [];
        for (var i = 0; i < this.length; i++) {
            if (!n[this[i]]) {
                n[this[i]] = true;
                r.push(this[i]);
            }
        }
        return r;
    };
    console.log(arr.unique3());


    //数组排序
    //第一种方法
    //冒泡排序
    function bubbleSort2(arr) {
        for (var i = arr.length - 1; i > 0; i--) {
            for (var j = 0; j < i; j++) {
                if (arr[j] > arr[j + 1]) {
                    var temp = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j + 1] = temp;
                }
            }
        }
    }
    bubbleSort2(arr);
    console.log(arr);

    //选择排序
    function selectSort(arr) {
        for (var i = 0; i < arr.length - 1; i++) {
            for (var j = i + 1; j < arr.length - 1; j++) {
                if (arr[i] > arr[j]) {
                    var temp = arr[i];
                    arr[i] = arr[j];
                    arr[j] = temp;
                }
            }
        }
    }

    selectSort(arr);
    console.log(arr)
</script>

</html>